home *** CD-ROM | disk | FTP | other *** search
- Path: news.cc.utah.edu!not-for-mail
- From: dpncc@utah.state.ut.us (NCC Network)
- Newsgroups: comp.unix.programmer,comp.lang.c,comp.unix.internals
- Subject: C compiler Error on EXEC SQL
- Date: 12 Apr 1996 02:19:14 GMT
- Organization: University of Utah Computer Center
- Message-ID: <4kkej2$3ta@news.cc.utah.edu>
- NNTP-Posting-Host: utah.it.as.ex.state.ut.us
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
-
- Hi
-
- I post this for my friend who has no access to the internet and would like to
- get help from C experts in the Net. She has a C program left over from a guy
- left the company. The C source code is included below as well as the compiler
- error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't seem
- to be a standard C.
-
- I would appreciate any hints or comments.
- Thanks in advances.
-
- Dennis.
-
-
- -------------------- ERROR MESSAGE ----------------------------------------
-
- I tried to compile "monthly_addup.c" and get the following error message:
-
- (Bundled) cc: line 4: error 1000: Unexpected symbol: "SQL".
- (Bundled) cc: line 4: error 1000: Unexpected symbol: ";".
- (Bundled) cc: line 12: error 1000: Unexpected symbol: "SQL".
- (Bundled) cc: line 12: error 1000: Unexpected symbol: "DECLARE".
- (Bundled) cc: line 24: error 1000: Unexpected symbol: "SQL".
- (Bundled) cc: line 24: error 1000: Unexpected symbol: "DECLARE".
- (Bundled) cc: line 50: error 1000: Unexpected symbol: "SQL".
- (Bundled) cc: line 50: error 1000: Unexpected symbol: "'revenue'".
- ...............................
-
- ----------------------------- C program ----------------------------
- This C program is originally named as "monthly_addup.ec". It's not like
- the normal C program that ends with ".c".
- Here is the source:
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- EXEC SQL include decimal.h;
-
- /* Global variables */
- char month[3]; /* mm plus null zero to end string */
- char year[5]; /* yyyy plus null zero to end string */
- char month_name[10]; /* ex: September plus null zero to end string */
-
- EXEC SQL BEGIN DECLARE SECTION;
- long per_id_revn_de;
- long loc_id_revn_de;
- long ind_id_revn_de;
- long ct_id_revn_de;
- long fee_id_revn_de;
- long dist_id_revn_de;
- dec_t amt_paid_revn_de;
- dec_t amt_credit_revn_de;
- dec_t amt_due_revn_de;
- long trans_count_p_revn_de;
- long trans_count_c_revn_de;
- long trans_count_d_revn_de;
- EXEC SQL END DECLARE SECTION;
-
- EXEC SQL BEGIN DECLARE SECTION;
- long per_id_perd_de;
- char per_level_perd_de[16]; /* additional byte for null zero */
- char per_desc_perd_de[16];
- char week_perd_de[11];
- char month_perd_de[11];
- char quarter_perd_de[11];
- char year_perd_de[5];
- char fiscal_year_perd_de[6];
- int sequence_perd_de;
- int per_num_perd_de;
- char cur_flag_perd_de;
- EXEC SQL END DECLARE SECTION;
-
- /* Main Program */
- main(argc,argv)
- int argc;
- char *argv[];
- {
-
- long per_id_for_month;
- int num_recs_created = 0;
- char mmyyyy[7];
- char filename[40];
- double amt_paid, amt_credit, amt_due;
- int x;
- FILE *fptr;
-
- if (argc == 3)
- ;
- else
- {
- printf("Incorrect number of arguements\n");
- printf("Usage: %s [mmyyyy] [output file and path] \n",argv[0]);
- exit(8);
- }
-
- if (strlen(argv[2]) > 40)
- {
- printf("Path and filename arguement too long. ");
- printf("Must not exceed 40 characters\n");
- exit(8);
- }
-
- printf("\nMonthly Addup Program is running...\n\n");
-
- strcpy(mmyyyy, argv[1]);
- strcpy(filename, argv[2]);
-
- printf("Monthly data will be written to output file: %s\n", filename);
-
- if ( (fptr = fopen(filename,"w")) == NULL )
- {
- printf("Cannot open output file: %s\n", filename);
- exit(8);
- }
-
- edit_and_convert_date(mmyyyy);
-
- printf("Monthly data is being generated for: %s %s\n",month_name, year);
-
- EXEC SQL connect to 'revenue';
- if (SQLCODE != 0)
- {
- printf("SQL Error occurred on connect to database. ");
- printf("SQLCODE is: %d\n", SQLCODE);
- exit(8);
- }
-
- EXEC SQL declare get_revenue cursor for
- select loc_id,
- ind_id,
- ct_id,
- fee_id,
- dist_id,
- sum(amt_paid),
- sum(amt_credit),
- sum(amt_due),
- sum(trans_count_p),
- sum(trans_count_c),
- sum(trans_count_d)
- into :loc_id_revn_de,
- :ind_id_revn_de,
- :ct_id_revn_de,
- :fee_id_revn_de,
- :dist_id_revn_de,
- :amt_paid_revn_de,
- :amt_credit_revn_de,
- :amt_due_revn_de,
- :trans_count_p_revn_de,
- :trans_count_c_revn_de,
- :trans_count_d_revn_de
- from revenue
- where per_id in (select per_id
- from period
- where per_level = "Week" and
- month = :month_perd_de and
- year = :year_perd_de)
- group by loc_id, ind_id, ct_id, fee_id, dist_id
- FOR READ ONLY;
-
-
- strcpy(year_perd_de,year);
- strcpy(month_perd_de,month_name);
-
- EXEC SQL
- select per_id
- into :per_id_perd_de
- from period
- where per_level = "Month" and
- month = :month_perd_de and
- year = :year_perd_de;
-
- per_id_for_month = per_id_perd_de;
-
- strcpy(month_perd_de,month_name);
- strcpy(year_perd_de,year);
- EXEC SQL open get_revenue;
- if (SQLCODE != 0)
- {
- printf("SQL Error occurred on open cursor get_revenue. ");
- printf("SQLCODE is: %d\n", SQLCODE);
- exit(8);
- }
-
- EXEC SQL fetch get_revenue;
- while (SQLCODE == 0)
- {
- if (x = dectodbl(&amt_paid_revn_de, &amt_paid))
- {
- printf("Error %d converting DECIMAL amt_paid_revn_de to DOUBLE\n",x);
- exit(8);
- }
- if (x = dectodbl(&amt_credit_revn_de, &amt_credit))
- {
- printf("Error %d converting DECIMAL amt_credit_revn_de to DOUBLE\n",x);
- exit(8);
- }
- if (x = dectodbl(&amt_due_revn_de, &amt_due))
- {
- printf("Error %d converting DECIMAL amt_due_revn_de to DOUBLE\n",x);
- exit(8);
- }
-
- fprintf(fptr, "%ld|",per_id_for_month);
- fprintf(fptr, "%ld|",loc_id_revn_de);
- fprintf(fptr, "%ld|",ind_id_revn_de);
- fprintf(fptr, "%ld|",ct_id_revn_de);
- fprintf(fptr, "%ld|",fee_id_revn_de);
- fprintf(fptr, "%ld|",dist_id_revn_de);
- fprintf(fptr, "%.2f|",amt_paid);
- fprintf(fptr, "%.2f|",amt_credit);
- fprintf(fptr, "%.2f|",amt_due);
- fprintf(fptr, "%ld|",trans_count_p_revn_de);
- fprintf(fptr, "%ld|",trans_count_c_revn_de);
- fprintf(fptr, "%ld|",trans_count_d_revn_de);
- fprintf(fptr, "\n");
-
- num_recs_created = num_recs_created + 1;
- EXEC SQL fetch get_revenue;
-
- }
-
- if (SQLCODE != 0 && SQLCODE != 100)
- {
- printf("SQLCODE is: %d\n",SQLCODE);
- exit(8);
- }
-
- printf("Number of load records created: %d\n",num_recs_created);
-
- fclose(fptr);
-
- EXEC SQL close get_revenue;
- EXEC SQL free get_revenue;
-
- EXEC SQL disconnect current;
-
- printf("\nMonthly Addup Program completed...\n\n");
- return(0);
- }
-
-
- /* Function to edit the month and year entered. Convert the month */
- /* to a literal (02 --> February) */
-
- edit_and_convert_date(mmyyyy)
- char *mmyyyy;
-
- {
- int i, j;
- int month_num, year_num;
-
- j=0;
- for (i=0; i<2; i++)
- {
- month[j] = mmyyyy[i];
- j++;
- }
- month[j] = '\0';
-
- j=0;
- for (i=2; i<6; i++)
- {
- year[j] = mmyyyy[i];
- j++;
- }
- year[j] = '\0';
-
- month_num = atoi(month);
- year_num = atoi(year);
-
- switch (month_num)
- {
- case 1: strcpy(month_name,"January");
- break;
- case 2: strcpy(month_name,"February");
- break;
- case 3: strcpy(month_name,"March");
- break;
- case 4: strcpy(month_name,"April");
- break;
- case 5: strcpy(month_name,"May");
- break;
- case 6: strcpy(month_name,"June");
- break;
- case 7: strcpy(month_name,"July");
- break;
- case 8: strcpy(month_name,"August");
- break;
- case 9: strcpy(month_name,"September");
- break;
- case 10: strcpy(month_name,"October");
- break;
- case 11: strcpy(month_name,"November");
- break;
- case 12: strcpy(month_name,"December");
- break;
- default: printf("Invalid month value. Value is: %d\n",month_num);
- exit(8);
- }
-
- if (year_num > 1900 && year_num < 2100)
- ;
- else
- {
- printf("Invalid year value. Value is: %d\n",year_num);
- exit(8);
- }
- }
-
-